layui.use(["layer","laydate","jquery"],function () {
    var
        layer = layui.layer,
        laydate = layui.laydate,
        $ = layui.jquery;
    var list = [];
    getTotalAmountOfGoodsOnShelf();
    function getTotalAmountOfGoodsOnShelf(){
        //查询上架商品总数
        $.ajax({
            url:"/HomePage/TotalAmountOfGoodsOnShelf",
            data:{"type":3,"result":1,"productSate":1},
            type:'post',
            dataType:"json",
            success:function (data) {
                //审核成功且上架商品总量
                $("#TotalAmountOfGoodsOnShelf").text(data.data);
                $("#ProductCount").text(data.data);
            }
        })
    }
    getTotalVideoOverhead();
    function getTotalVideoOverhead(){
        //查询上架课程总数
        $.ajax({
            url:"/HomePage/TotalVideoOverhead",
            data:{"courseCstatus":1,"courseStatus":2},
            type:'post',
            dataType:"json",
            success:function (data) {
                $("#TotalVideoOverhead").text(data.data);
                $("#CourseCount").text(data.data);
            }
        })
    }
    getTotalWebUser();
    function getTotalWebUser(){
        //查询前端用户人数
        $.ajax({
            url:"/HomePage/getTotalWebUser",
            data:{"status":4},
            type:'post',
            dataType:"json",
            success:function (data) {
                //查询商品销售总量
                $("#TotalWebUser").text(data.data);
            }
        })
    }
    getTotalBackstageUser();
    function getTotalBackstageUser(){
        //查询后端端用户人数
        $.ajax({
            url:"/HomePage/getTotalBackstageUser",
            data:{"status":2},
            type:'post',
            dataType:"json",
            success:function (data) {
                //查询商品销售总量
                $("#TotalBackstageUser").text(data.data);
            }
        })
    }
    getCreatorExmaine();
    function getCreatorExmaine(){
        //查询创作者待认证信息
        $.ajax({
            url:"/HomePage/getCreatorExmaine",
            data:{"result":1},
            type:'post',
            dataType:"json",
            success:function (data) {
                //查询创作者待认证信息
                $("#CreatorExmaine").text(data.data);
            }
        })
    }
    getTotalNumberOfCompletedOrders();
    function getTotalNumberOfCompletedOrders(){
        //查询微圈发布总数
        $.ajax({
            url:"/HomePage/TotalNumberOfCompletedOrders",
            data:{"orderStatus":6},
            type:'post',
            dataType:"json",
            success:function (data) {
                //已完成订单总数
                $("#TotalNumberOfCompletedOrders").text(data.data);
            }
        })
    }
    getTotalProductStayExamine();
    function getTotalProductStayExamine(){
        //查询商品待审核信息
        $.ajax({
            url:"/HomePage/TotalProductStayExamine",
            data:{"type":3,"result":2},
            type:'post',
            dataType:"json",
            success:function (data) {
                //商品待审核信息总数
                $("#TotalProductStayExamine").text(data.data);
            }
        })
    }
    getTotalCourseStayExamine();
    function getTotalCourseStayExamine(){
        //查询课程待审核信息
        $.ajax({
            url:"/HomePage/TotalCourseStayExamine",
            data:{"type":2,"result":2},
            type:'post',
            dataType:"json",
            success:function (data) {
                //商品待审核信息总数
                $("#TotalCourseStayExamine").text(data.data);
            }
        })
    }
    getTotalMicroCircleStayExamine();
    function getTotalMicroCircleStayExamine(){
        //查询微圈待审核信息
        $.ajax({
            url:"/HomePage/TotalMicroCircleStayExamine",
            data:{"type":4,"result":2},
            type:'post',
            dataType:"json",
            success:function (data) {
                //商品待审核信息总数
                $("#TotalMicroCircleStayExamine").text(data.data);
            }
        })
    }
    getTotalOrders();
    function getTotalOrders(){
        //查询订单总数
        $.ajax({
            url:"/HomePage/getTotalOrders",
            data:{},
            type:'post',
            dataType:"json",
            success:function (data) {
                //查询订单总数
                $("#TotalOrders").text(data.data);
            }
        })
    }
    $.ajax({
        url:"/HomePage/getAllUsersRegistrationTime",
        data:{},
        type:'post',
        dataType:'json',
        success:function (data) {
            $("#todayUser").text(data.data.todayUser);
            $("#yesterdayUser").text(data.data.yesterdayUser);
            $("#monthUser").text(data.data.monthUser);
            $("#AllUsers").text(data.data.AllUsers);
        }
    });
    $("#refresh").click(function () {
        location.reload();
    });

    //待审核跳转
    $("#pendingTransactionTextshangpin").click(function () {
        if ($("#pendingTransactionTextshangpin").text() == "商品待审核信息"){
            parent.tabParentChange(34);
        }
    });
    $("#pendingTransactionTextkecheng").click(function () {
        if ($("#pendingTransactionTextkecheng").text() == "课程待审核信息"){
            parent.tabParentChange(36);
        }
    });
    $("#pendingTransactionTextweiqvan").click(function () {
        if ($("#pendingTransactionTextweiqvan").text() == "微圈待审核信息"){
            parent.tabParentChange(38);
        }
    });
    $("#pendingTransactionTextchuangzuozhe").click(function () {
        if ($("#pendingTransactionTextchuangzuozhe").text() == "创作者认证待处理信息"){
            parent.tabParentChange(81);
        }
    });

    //快捷入口跳转
    $("#user_list").click(function () {
        if ($("#user_list").text() == "用户列表"){
            parent.tabParentChange(74);
        }
    });
    $("#product_list").click(function () {
        if ($("#product_list").text() == "商品列表"){
            parent.tabParentChange(9);
        }
    });
    $("#course_list").click(function () {
        if ($("#course_list").text() == "课程列表"){
            parent.tabParentChange(16);
        }
    });
    $("#microcircle_list").click(function () {
        if ($("#microcircle_list").text() == "微圈列表"){
            parent.tabParentChange(23);
        }
    });
    $("#course_order").click(function () {
        if ($("#course_order").text() == "课程订单"){
            parent.tabParentChange(43);
        }
    });
    $("#course_audit").click(function () {
        if ($("#commodity_order").text() == "商品订单"){
            parent.tabParentChange(45);
        }
    });
    $("#coupon_list").click(function () {
        if ($("#coupon_list").text() == "优惠券列表"){
            parent.tabParentChange(51);
        }
    });
    $("#carousel_chart_list").click(function () {
        if ($("#carousel_chart_list").text() == "轮播图列表"){
            parent.tabParentChange(56);
        }
    });



    CourseStatistics = function CourseStatistics() {
        CourseStatistics2();
    }
    //课程统计
    CourseStatistics2();
    function CourseStatistics2(){
        $.ajax({
            url:"/HomePage/getAllCreateDate",
            data:{"courseStatus":2,"courseCstatus":4},
            type:'post',
            dataType:'json',
            success:function (data) {
                $("#WeekCourseBox").show();
                $("#WeekProductBox").css("display","none");
                $("#WeekUserBox").css("display","none");
                list = [];
                list.push(data.data.yi);
                list.push(data.data.er);
                list.push(data.data.san);
                list.push(data.data.si);
                list.push(data.data.wu);
                list.push(data.data.liu);
                list.push(data.data.qi);
                CourseWeek(list);
            }
        });
        //获取本周与上周课程数量
        $.ajax({
            url:"/HomePage/TotalOfThisWeekAndLastWeekCreateDate",
            data:{"courseStatus":2,"courseCstatus":4},
            type:'post',
            dataType:'json',
            success:function (data) {
                var thisWeek = data.data.thisWeek;
                $("#ThisWeekCourse").text(thisWeek);
                var lastWeek = data.data.lastWeek;
                $("#LastWeekCourse").text(lastWeek);
                var a = Number(thisWeek)/Number(lastWeek);
                if(Number(thisWeek)==0 && Number(lastWeek)!=0){
                    a =Number(lastWeek) *100+"%";
                    $("#WeekCourseQuantity").text("-"+a);
                }
                if (Number(thisWeek)!=0 && Number(lastWeek)==0) {
                    a =Number(thisWeek) *100+"%";
                    $("#WeekCourseQuantity").text(a);
                    $("#WeekCourseQuantity").css("color","red");
                }
                if (Number(thisWeek)==Number(lastWeek)){

                    $("#WeekCourseQuantity").text("0%");
                    $("#WeekCourseQuantity").css("color","red");
                }else if(a>=1){
                    a =a *100+"%";
                    $("#WeekCourseQuantity").text(a);
                    $("#WeekCourseQuantity").css("color","red");
                }else if(a<1){
                    a =(a-1) *100+"%";
                    $("#WeekCourseQuantity").text("-"+a);
                }

            }
        });
    }

    //商品统计
    ProductStatistics = function ProductStatistics(){
        $.ajax({
            url:"/HomePage/getAllProductCreateDate",
            data:{"productSate":1},
            type:'post',
            dataType:'json',
            success:function (data) {
                $("#WeekCourseBox").css("display","none");
                $("#WeekProductBox").show();
                $("#WeekUserBox").css("display","none");
                list = [];
                list.push(data.data.yi);
                list.push(data.data.er);
                list.push(data.data.san);
                list.push(data.data.si);
                list.push(data.data.wu);
                list.push(data.data.liu);
                list.push(data.data.qi);
                ProductWeek(list);
            }
        });
        //获取本周与上周课程数量
        $.ajax({
            url:"/HomePage/TotalOfThisWeekAndLastWeekProductCreateDate",
            data:{"productSate":1},
            type:'post',
            dataType:'json',
            success:function (data) {
                var thisWeek = data.data.thisWeek;
                $("#ThisWeekProduct").text(thisWeek);
                var lastWeek = data.data.lastWeek;
                $("#LastWeekProduct").text(lastWeek);
                /*var a = Number(thisWeek)/Number(lastWeek);*/
                if(Number(thisWeek)==0 && Number(lastWeek)!=0){
                    a =Number(lastWeek) *100+"%";
                    $("#WeekProductQuantity").text("-"+a);
                }
                if (Number(thisWeek)!=0 && Number(lastWeek)==0) {
                    a =Number(thisWeek) *100+"%";
                    $("#WeekProductQuantity").text(a);
                    $("#WeekProductQuantity").css("color","red");
                }
                if (Number(thisWeek)==Number(lastWeek)){

                    $("#WeekProductQuantity").text("0%");
                    $("#WeekProductQuantity").css("color","red");
                }else if(a>=1){
                    a =a *100+"%";
                    $("#WeekProductQuantity").text(a);
                    $("#WeekProductQuantity").css("color","red");
                }else if(a<1){
                    a =a *100+"%";
                    $("#WeekProductQuantity").text(a);
                }

            }
        });
    }
    //用户统计
    UserStatistics = function UserStatistics(){
        $.ajax({
            url:"/HomePage/getAllUserCreateDate",
            data:{},
            type:'post',
            dataType:'json',
            success:function (data) {
                $("#WeekCourseBox").css("display","none");
                $("#WeekProductBox").css("display","none");
                $("#WeekUserBox").show();
                list = [];
                list.push(data.data.yi);
                list.push(data.data.er);
                list.push(data.data.san);
                list.push(data.data.si);
                list.push(data.data.wu);
                list.push(data.data.liu);
                list.push(data.data.qi);
                UserWeek(list);
            }
        });
        //获取本周与上周课程数量
        $.ajax({
            url:"/HomePage/TotalOfThisWeekAndLastWeekUserCreateDate",
            data:{},
            type:'post',
            dataType:'json',
            success:function (data) {
                var thisWeek = data.data.thisWeek;
                $("#ThisWeekUser").text(thisWeek);
                var lastWeek = data.data.lastWeek;
                $("#LastWeekUser").text(lastWeek);
                var a = Number(thisWeek)/Number(lastWeek);
                if(Number(thisWeek)==0 && Number(lastWeek)!=0){
                    a =Number(lastWeek) *100+"%";
                    $("#WeekUserQuantity").text("-"+a);
                }
                if (Number(thisWeek)!=0 && Number(lastWeek)==0) {
                    a =Number(thisWeek) *100+"%";
                    $("#WeekUserQuantity").text(a);
                    $("#WeekUserQuantity").css("color","red");
                }
                if (Number(thisWeek)==Number(lastWeek)){

                    $("#WeekUserQuantity").text("0%");
                    $("#WeekUserQuantity").css("color","red");
                }else if(a>=1){
                    a =a *100+"%";
                    $("#WeekCourseQuantity").text(a);
                    $("#WeekCourseQuantity").css("color","red");
                }else if(a<1){
                    a =(a-1) *100+"%";
                    $("#WeekUserQuantity").text("-"+a);
                }
            }
        });
    }
    //echarts表格
    function CourseWeek(data){
        var chartDom = document.getElementById('main');
        var myChart = echarts.init(chartDom);
        var option;

        option = {
            xAxis: {
                type: 'category',
                data: ['星期一', '星期二', '星期三', '星期四','星期五','星期六','星期日']
            },
            yAxis: {
                type: 'value'
            },
            series: [
                {
                    data:data,
                    type: 'line'
                }
            ]
        };

        option && myChart.setOption(option);
    }
    function ProductWeek(data){
        var chartDom = document.getElementById('main');
        var myChart = echarts.init(chartDom);
        var option;

        option = {
            xAxis: {
                type: 'category',
                data: ['星期一', '星期二', '星期三', '星期四','星期五','星期六','星期日']
            },
            yAxis: {
                type: 'value'
            },
            series: [
                {
                    data:data,
                    type: 'line'
                }
            ]
        };

        option && myChart.setOption(option);
    }
    function UserWeek(data){
        var chartDom = document.getElementById('main');
        var myChart = echarts.init(chartDom);
        var option;

        option = {
            xAxis: {
                type: 'category',
                data: ['星期一', '星期二', '星期三', '星期四','星期五','星期六','星期日']
            },
            yAxis: {
                type: 'value'
            },
            series: [
                {
                    data:data,
                    type: 'line'
                }
            ]
        };

        option && myChart.setOption(option);
    }
    refresh = function refresh(){
        location.reload();
    }
});